//快速排序的思想是什么？??
//快速排序的思想就是递归分治。从一个基准开始二分

const arr = [2,1,1,4,3,6,8,7]
const quickSort = (arr)=>{
    if(arr.length<=1) return arr
    let mid = Math.floor(arr.length-1/2)//取得一个基准值
    let left = []
    let right = []
    for(let i=0;i<arr.length;i++){
        if(i!==mid){
            if(arr[i]<=arr[mid]){
                left.push(arr[i])
            }else{
                right.push(arr[i])
            }
        }
       
    }
    return [...quickSort(left),arr[mid],...quickSort(right)]
}
console.log(quickSort(arr));
